<?php

namespace StarCloud\Services\Export\Boss;

use Phalcon\Db\Column;
use StarCloud\Models\StarCloud\Company;
use StarCloud\Models\StarCloud\CompanyRegister;
use StarCloud\Services\Export\BaseExport;

class CheckPassCompanyListService extends BaseExport
{
    protected function invoke(array $arrInput)
    {
        //筛选条件：状态
        $arrConditions = [
            'conditions' => 'status = :status:',
            'bind' => [
                'status' => CompanyRegister::STATUS_PASS
            ],
            'bindTypes' => [
                'status' => Column::BIND_PARAM_INT,
            ],
            'order' => 'id DESC',
        ];

        $list = CompanyRegister::getPaginatorArrayResult($arrConditions, $arrInput['page'], $arrInput['count']);
        $list = Company::fillArrayRelation('profile', 'company_uid', $list, 'company_uid');

        $this->arrOutput = $list;

        return $list;
    }

    public function getFileHeader()
    {
        return [
            '编号',
            '单位全称',
            '上级单位',
            '会员类型',
            '账号',
            '负责人',
            '负责人手机号',
            '联络人',
            '联络人手机号',
            '状态',
        ];
    }

    public function lineMap($item)
    {
        $companyConfig = self::getConfig()['common/company'];

        $arr = [
            $item['company_uid'],
            $item['profile']['company_name'],
            $item['profile']['parent_name'],
            $companyConfig['type'][$item['profile']['company_type']] ?? '',
            $item['account'],
            $item['profile']['manager_name'],
            $item['profile']['manager_mobile'],
            $item['profile']['contact_name'],
            $item['profile']['contact_mobile'],
            $item['status'] == CompanyRegister::STATUS_PASS ? "审核通过" : "",
        ];

        return $this->convertToGB2312($arr);
    }
}
